package com.maxlen.goods.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
@EnableConfigurationProperties(MyThreadPoolConfigProperties.class)
public class MyThreadPoolConfig {

    @Autowired
    private MyThreadPoolConfigProperties configProperties;

    @Bean
    ThreadPoolExecutor threadPoolExecutor(){
        return new ThreadPoolExecutor(
                configProperties.getCorePoolSize(),
                configProperties.getMaximumPoolSize(),
                configProperties.getKeepAliveTime(),
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(100000),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }

}
